package com.travel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.travel.domain.entity.ScenicProfile;
import com.travel.service.ScenicProfileService;
import com.travel.mapper.ScenicProfileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 李健波
* @description 针对表【scenic_profile】的数据库操作Service实现
* @createDate 2024-11-20 11:11:13
*/
@Service
public class ScenicProfileServiceImpl extends ServiceImpl<ScenicProfileMapper, ScenicProfile>
    implements ScenicProfileService{
    @Autowired
    private ScenicProfileMapper scenicProfileMapper;
    @Override
    public List<ScenicProfile> listAllProfiles() {
        return scenicProfileMapper.selectList(null);
    }
    public List<ScenicProfile> filterScenicProfiles(Long typeId, Long areaId,String name) {
        LambdaQueryWrapper<ScenicProfile> queryWrapper = new LambdaQueryWrapper<>();

        // 按类型筛选
        if (typeId != null) {
            queryWrapper.eq(ScenicProfile::getTypeId, typeId);
        }

        // 按区域筛选
        if (areaId != null) {
            queryWrapper.eq(ScenicProfile::getAreasId, areaId);
        }

        // 按名称模糊查询
        if (name != null && !name.isEmpty()) {
            queryWrapper.like(ScenicProfile::getName, name);
        }
        // 执行查询
        return scenicProfileMapper.selectList(queryWrapper);
    }


    // 默认返回15条按距离排序的景点
    public List<ScenicProfile> getTop15ByDistance() {
        LambdaQueryWrapper<ScenicProfile> queryWrapper = new LambdaQueryWrapper<>();

        // 只返回前15条记录
        Page<ScenicProfile> page = new Page<>(1, 30);
        IPage<ScenicProfile> scenicProfiles = scenicProfileMapper.selectPage(page, queryWrapper);

        return scenicProfiles.getRecords();
    }

}




